package TOP101;

/**
 * @Question BM1
 * @Date 2022/11/1 10:10
 * @Solution
 */
public class BM1 {
    public ListNode ReverseList(ListNode head) {
        if (head == null) {
            return null;
        }
        if (head.next == null) {
            return head;
        }
        ListNode ans = new ListNode(head.val);
        ListNode cur = head.next;
        while (cur != null) {
            ListNode t = new ListNode(cur.val);
            t.next = ans;
            ans = t;
            cur = cur.next;
        }
        return ans;
    }
}
